var dlTabsPrefs = {

	init : function()
	{
		this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
					.getService(Components.interfaces.nsIPrefService);
					
		this.display = this.prefs.getBranch("downloadtabs.display.");
		this.display.QueryInterface(Components.interfaces.nsIPrefBranch2);
		this.display.addObserver("", this, false);
		
		this.filters = this.prefs.getBranch("downloadtabs.filters.");
		
		this.field = this.prefs.getBranch("downloadtabs.field.");
		this.field.QueryInterface(Components.interfaces.nsIPrefBranch2);
		this.field.addObserver("", this, false);
		
		this.behavior = this.prefs.getBranch("downloadtabs.behavior.");
	},
	
	// Display
	
	getDisplayPref : function(pref)
	{
		return(this.display.getIntPref(pref));
	},
	
	// Filter
	
	getFilterLocation : function(i){					return("downloadtabs.filters.filter" + i); 					},
	
	getNumFilters : function(){		if(this.filters)	return(this.filters.getIntPref("number")); 					},
	getFilterRegex : function(i){	if(this.filters)	return(this.filters.getCharPref("filter" + i + ".regex"));	},
	getFilterTime : function(i){	if(this.filters)	return(this.filters.getIntPref("filter" + i + ".time"));	},
	
	setNumFilters : function(num){		if(this.filters)	return(this.filters.setIntPref("number", num));				},
	setFilterRegex : function(i, regex){if(this.filters)	this.filters.setCharPref("filter" + i + ".regex", regex);	},
	setFilterTime : function(i, time){	if(this.filters)	this.filters.setIntPref("filter" + i + ".time", time);	},
	
	match : function(dl)
	{
		var filename = dl.displayName;
		var num = this.getNumFilters();
		for(var i = 0; i < num; i++)
		{
			var regex = this.getFilterRegex(i);
			var obj = new RegExp(regex);
			if(obj)
			{
				if(obj.exec(filename))
				{
					return(this.getFilterTime(i));
				}
			}
		}
		// Not found = -2
		return(-2);
	},
	
	// Field
	
	getETAField : function(){	if(this.field)	return(this.field.getIntPref("ETA"));},
	getSpeedField : function(){	if(this.field)	return(this.field.getIntPref("Speed"));},
	getSizeField : function(){	if(this.field)	return(this.field.getIntPref("Size"));},
	
	getField : function(i){		if(this.field)	return(this.field.getCharPref("field" + i));},
	
	setField : function(i, field)
	{
		if(this.field)
		{
			this.field.setIntPref(field, i);
			this.field.setCharPref("field" + i, field);
		}
	},
	
	// downloadtabs.display or field was changed
	observe: function(subject, topic, data)
	{
		 if(topic == "nsPref:changed")
		 {
			if(dlTabsTab)
			{
				dlTabsTab.refresh();
			}
		 }
	},
	
	// Behavior
	getAutoOpen : function() { return(this.behavior.getCharPref("autoopen")); },
	getAutoRefresh : function() { return(this.behavior.getBoolPref("autorefresh")); }
};